USE AdventureWorksLT
GO
EXEC ('DROP TABLE DrillAttr')
EXEC ('DROP TABLE DrillRow')
EXEC ('DROP TABLE MSystem')
EXEC ('DROP TABLE MAttribute')
GO
CREATE TABLE DrillAttr(FK_SystemID int,FK_Attribute int,
	CS_Attr bigint,CS_Row bigint,
	AttrValue nvarchar(4000),AttrDescription nvarchar(4000),
	CS_DrillAttr AS dbo.Cs6(FK_SystemID,FK_Attribute,CS_Attr,CS_Row,AttrValue,AttrDescription))
GO
CREATE UNIQUE NONCLUSTERED INDEX ixDrillAttr ON dbo.DrillAttr(CS_DrillAttr)WITH(IGNORE_DUP_KEY=ON)
INSERT DrillAttr SELECT 1,2,dbo.Cs1(3),dbo.Cs1(4),5,6 UNION SELECT 1,2,dbo.Cs1(3),dbo.Cs1(4),5,6 UNION SELECT 1,2,dbo.Cs1(3),dbo.Cs1(4),5,7
SELECT * FROM DrillAttr
GO
CREATE TABLE DrillRow(FK_SystemID int,
	RowID bigint,
	CS_Row bigint,
	RowValue nvarchar(4000),
	RowDescription nvarchar(4000),
	CS_DrillRow AS dbo.Cs5(FK_SystemID,RowID,CS_Row,RowValue,RowDescription))	
GO
CREATE UNIQUE NONCLUSTERED INDEX ixDrillRow ON dbo.DrillRow(CS_DrillRow)WITH(IGNORE_DUP_KEY=ON)
INSERT DrillRow SELECT 1,2,dbo.Cs1(3),4,5 UNION SELECT 1,2,dbo.Cs1(3),4,5 UNION SELECT 1,2,dbo.Cs1(3),4,6
SELECT * FROM DrillRow
GO
CREATE TABLE MSystem(SystemID int, SystemName nvarchar(4000))
GO
INSERT MSystem VALUES (1,'AdventureWorksLT')
GO
CREATE TABLE MAttribute(AttributeID int, FK_SystemID int, AttributeName nvarchar(4000))
GO
INSERT MAttribute VALUES (1,1,'PostalNO')
SELECT a.*,s.* FROM MAttribute a JOIN MSystem s ON a.FK_SystemID=s.SystemID--SELECT a.AttributeID,s.SystemID FROM MAttribute a JOIN MSystem s ON a.FK_SystemID=s.SystemID WHERE s.SystemName='AdventureWorksLT' AND a.AttributeName='PostalNO'
